#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""  
@Project : pythonProject
@File : whrval.py
@Author : 孔雀
@Time : 2025/9/9 17:01  
@脚本说明 : 

"""

import argparse

from tools.mysql_val import mysql_run
from tools.redis_val import redis_run
from tools.ip_val import run_ip
from tools.ccolor import Colors

banner = """
____              ___ ____    ___________  ____     ___ ____     ______     
`Mb(      db      )d' `MM'    `MM`MMMMMMMb.`Mb(     )d' `MM'     `M`MM'     
 YM.     ,PM.     ,P   MM      MM MM    `Mb YM.     ,P   MM       M MM      
 `Mb     d'Mb     d'   MM      MM MM     MM `Mb     d'   MM       M MM      
  YM.   ,P YM.   ,P    MM      MM MM     MM  YM.   ,P    MM       M MM      
  `Mb   d' `Mb   d'    MMMMMMMMMM MM    .M9  `Mb   d'    MM       M MM      
   YM. ,P   YM. ,P     MM      MM MMMMMMM9'   YM. ,P     MM       M MM      
   `Mb d'   `Mb d'     MM      MM MM  \M\     `Mb d'     MM       M MM      
    YM,P     YM,P      MM      MM MM   \M\     YM,P      YM       M MM      
    `MM'     `MM'      MM      MM MM    \M\    `MM'       8b     d8 MM    / 
     YP       YP      _MM_    _MM_MM_    \M\_   YP          (v1.2) by zhangsan & whr 
"""

print(f"{Colors.BLUE_BRIGHT}{Colors.BOLD}{banner}{Colors.RESET}")
# 创建命令行解析器对象
parser = argparse.ArgumentParser(description="智慧AI漏扫")
subparsers = parser.add_subparsers(help="选择要使用的功能", dest="sub_command")

# 创建MySQL的解析器对象
mysql_subparsers = subparsers.add_parser("mysql", help="MySQL相关漏扫")
mysql_subparsers.add_argument("--host", "-H", dest="host", type=str, default="127.0.0.1", help="MySQL主机地址")
mysql_subparsers.add_argument("--port", "-P", dest="port", type=int, default=3306, help="MySQL端口号")
mysql_subparsers.add_argument("--username", "-u", dest="username", type=argparse.FileType(mode='r', encoding="utf-8"),
                              default="./dict/user.dict", help="MySQL用户名")
mysql_subparsers.add_argument("--password", "-p", dest="password", type=argparse.FileType(mode='r', encoding="utf-8"),
                              default="./dict/passwd.dict", help="MySQL密码本")

# 创建Redis的解析器对象
redis_subparsers = subparsers.add_parser("redis", help="Redis相关漏扫")
redis_subparsers.add_argument("--host", "-H", dest="host", type=str, default="127.0.0.1", help="Redis主机地址")
redis_subparsers.add_argument("--port", "-P", dest="port", type=int, default=6379, help="Redis端口号")
redis_subparsers.add_argument("--password", "-p", dest="password", type=argparse.FileType(mode='r', encoding="utf-8"),
                              default="./dict/passwd.dict", help="Redis密码本")

# 创建IP的解析器对象
ip_subparsers = subparsers.add_parser("ip", help="主机相关漏扫")
ip_subparsers.add_argument("--host", "-H", dest="host", type=str, default="127.0.0.1", help="IP主机地址网段")
ip_subparsers.add_argument("--iface", "-f", dest="iface", type=str, default="以太网", help="扫描网卡")

args = parser.parse_args()

if args.sub_command == "mysql":
    mysql_run(args.host, args.port, args.username.readlines(), args.password.readlines())
elif args.sub_command == "redis":
    redis_run(args.host, args.port, args.password.readlines())
elif args.sub_command == "ip":
    run_ip(args.host, args.iface)
else:
    print("请选择要使用的功能")
